<template>
  <div class="language-switcher">
    <h3 class="section-title">{{ $t('settings.languageSettings') }}</h3>
    <div class="language-selector">
      <label for="language-select">{{ $t('settings.selectLanguage') }}</label>
      <select 
        id="language-select" 
        v-model="currentLanguage" 
        @change="changeLanguage"
        class="language-dropdown"
      >
        <option value="en">{{ $t('settings.english') }}</option>
        <option value="zh">{{ $t('settings.chinese') }}</option>
      </select>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue';
import { useI18n } from 'vue-i18n';
import { setLocale } from '@/i18n';

const { t, locale } = useI18n();
const currentLanguage = ref('');

onMounted(() => {
  currentLanguage.value = locale.value;
});

const changeLanguage = () => {
  setLocale(currentLanguage.value);
};
</script>

<style scoped>
.language-switcher {
  margin-top: 2rem;
  margin-bottom: 2rem;
}

.section-title {
  font-size: 1.5rem;
  margin-bottom: 1rem;
  color: #fff;
  font-weight: 600;
}

.language-selector {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.language-selector label {
  font-size: 1rem;
  color: #fff;
  opacity: 0.8;
}

.language-dropdown {
  padding: 0.75rem 1rem;
  background: rgba(0, 0, 0, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 0.5rem;
  color: #fff;
  font-size: 1rem;
  cursor: pointer;
  outline: none;
  transition: all 0.3s ease;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 1rem center;
  background-size: 1em;
  padding-right: 2.5rem;
}

.language-dropdown:hover {
  background-color: rgba(0, 0, 0, 0.8);
  border-color: #4A99E9;
}

.language-dropdown:focus {
  border-color: #4A99E9;
  box-shadow: 0 0 0 2px rgba(74, 153, 233, 0.3);
}

/* Style for the dropdown options */
.language-dropdown option {
  background-color: #1a1a1a;
  color: white;
}

@media (max-width: 768px) {
  .language-dropdown {
    padding: 0.6rem 0.8rem;
    font-size: 0.9rem;
  }
}
</style> 